<?php

class ConfigController extends \BaseController {

    /**
     * @param [string]  dbName      配置数据库名
     * @param [string]  prefix      表名前缀
     * @param [string]  dbUsername  数据库连接用户名
     * @param [string]  dbPassword  数据库连接密码
     * @return [array] [异常信息]
     */
    public function dbConfig(){
        // $servername = Input::get('servername');
        // $dbUsername = Input::get('dbUsername');
        // $dbPassword = Input::get('dbPassword');
        // $dbName = Input::get('dbName');
        // $prefix = Input::get('prefix');
        
        // $data = array(
        //         'servername' => $servername,
        //         'dbUsername' => $dbUsername,
        //         'dbPassword' => $dbPassword,
        //         'dbName' => $dbName,
        //         'prefix' => $prefix
        //     );

        $data = Input::all();
        $rules = array(
                    'servername' => 'required',
                    'dbUsername' => 'required',
                    'dbPassword' => 'required',
                    'dbName' => 'required',
                );
        BaseService::validateInputParam($data, $rules);
        $conn = ConfigService::getConnection($data);
        $result = ConfigService::createDataBase($data, $conn);
        ConfigService::migration();
        // $result = ConfigService::dropDataBase($data, $conn);

        return $result;
    }

}